package com.wuliu.controller;

import com.wuliu.common.annotation.RepeatSubmit;
import com.wuliu.common.core.domain.ApiResult;
import com.wuliu.common.core.domain.PageResult;
import com.wuliu.common.core.domain.entity.SysAppletUser;
import com.wuliu.common.utils.StringUtils;
import com.wuliu.system.domain.TspTrack;
import com.wuliu.system.domain.dto.applet.CustOrdersDto;
import com.wuliu.system.domain.dto.applet.QryOrderFeeDto;
import com.wuliu.system.domain.dto.applet.TspOrderPreDto;
import com.wuliu.system.domain.vo.applet.TspOrderPreVo;
import com.wuliu.system.service.ISysAppletUserService;
import com.wuliu.system.service.applet.AppletTspOrderPreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author realue
 * @version 1.0
 * @date 2023-10-30 15:57
 */

@RestController
@RequestMapping("/applet/order")
@Api(tags = {"预约单控制器"})
public class TspOrderPreController {
    @Resource
    private AppletTspOrderPreService tspOrderPreService;
    @Resource
    private ISysAppletUserService sysAppletUserService;

    @RepeatSubmit
    @ApiOperation(value = "创建订单")
    @PostMapping("/createOrder")
    public ApiResult<Integer> createOrder(@RequestBody @Validated TspOrderPreDto dto) {
        return ApiResult.success(tspOrderPreService.createOrder(dto));
    }

    @ApiOperation(value = "取消下单")
    @PostMapping("/cancelOrder")
    public ApiResult<Integer> cancelOrder(String id){
        return ApiResult.success(tspOrderPreService.cancelOrder(id));
    }

    @GetMapping("/getCustOrders")
    @ApiOperation(value = "查询我的收寄件", notes = "")
    public ApiResult<PageResult<TspOrderPreVo>> getCustOrders(CustOrdersDto dto) {
        return ApiResult.success(tspOrderPreService.getCustOrders(dto));
    }

    @GetMapping("/getTracks")
    @ApiOperation(value = "查询运单路由", notes = "")
    @ApiImplicitParam(name = "orderNo", value = "运单号", dataType = "String", paramType = "query")
    public ApiResult<List<TspTrack>> getTracks(String orderNo) {
        if (StringUtils.isEmpty(orderNo)) {
            ApiResult.error("运单号不能为空");
        }
        if (orderNo.length() < 6) {
            ApiResult.error("请输入长度大于5的运单号");
        }
        return ApiResult.success(tspOrderPreService.getTracks(orderNo));
    }

    @GetMapping("/getUserInfo")
    @ApiOperation(value = "业务员信息", notes = "")
    @ApiImplicitParam(name = "userId", value = "业务员id", dataType = "String", paramType = "query")
    public ApiResult<SysAppletUser> getUserInfo(Long userId) {
        return ApiResult.success(sysAppletUserService.selectSysAppletUserByUserId(userId));
    }

    @GetMapping("/calcFee")
    @ApiOperation(value = "运费查询", notes = "")
    public ApiResult<BigDecimal> calcFee(@Validated QryOrderFeeDto dto) {
        return ApiResult.success(tspOrderPreService.qryFee(dto));
    }
}
